es cheat sheet
http://elasticsearch-cheatsheet.jolicode.com
exploring cluster
cluster health
1 | 健康度 |
list all indices
1 | curl -X GET "localhost:9200/_cat/indices?v" |
create index
1 | 先创建一个index |
文档增删改查
插入并获取指定文档
1 | 插入 |
1 | 获取 |
更新文档
1 | update路径,修改name,并增加age |
删除文档
1 | curl -X DELETE "localhost:9200/customer/_doc/2?pretty" |
批量处理
1 | 插入俩文档,更新一个,删除一个 |
文档高级检索
1 | curl -X GET "localhost:9200/bank/_search" -H 'Content-Type: application/json' -d' |
匹配address包含mill的结果
1 | GET /bank/_search |
匹配address包含mill或者lane的结果
1 | GET /bank/_search |
匹配address包含”mill lane”短语的结果
1 | GET /bank/_search |
and 语句
1 | GET /bank/_search |
OR 语句
1 | GET /bank/_search |
must not
1 | GET /bank/_search |
must & must not
1 | GET /bank/_search |
检索优化
- query和filter的区别
query会计算相关度
filter不会计算相关度,而且检索结果会有缓存
1 | GET /bank/_search |
聚合
https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-aggregations.html
如果只需要聚合结果,size 填 0 即可
1 | GET /bank/_search |
1 | GET /bank/_search |